package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.CustomerReservationDto;
import com.zzyl.service.CustomerReservationService;
import com.zzyl.utils.UserThreadLocal;
import com.zzyl.vo.CustomerReservationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/customer/reservation")
@Api(tags = "客户端预约管理")
public class CustomerReservationController extends BaseController {

    @Autowired
    private CustomerReservationService customerReservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult getCancelledReservationCount(){
//        Long userId = UserThreadLocal.getUserId();
//        System.out.println(userId + "------------------");
        customerReservationService.queryDeclineReserNum();
        return success();
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult<List<CustomerReservationVo>> queryRestCountOnEveryTime(Long time){
        return success(customerReservationService.queryRestCountOnEveryTime(time));
    }

    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult addReservation(@RequestBody CustomerReservationDto customerReservationDto){
        customerReservationService.addReservation(customerReservationDto);
        return success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约")
    public ResponseResult<List<CustomerReservationVo>> queryPage(
            @ApiParam(value = "状态：0-待报道，1-已完成，2-取消，3-过期")
            @RequestParam(value = "status",required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize
    ){
        PageResponse<CustomerReservationVo> customerReservationVoPageResponse = customerReservationService
                .queryPage(pageNum,pageSize,status);
        return success(customerReservationVoPageResponse);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult cancelReservation(@PathVariable Long id){
        customerReservationService.cancelReservation(id);
        return success();
    }



}












